package ltd.followkba.comment.utils;

import java.util.List;

import ltd.advskin.MRAM;
import ltd.advskin.base.KcTwoListener;
import ltd.followkba.comment.banners.CBeanFile;
import ltd.followkba.comment.MBAPP;
import main.MAPI;

/**
 * Created by Administrator on 2018/4/14.
 */

public class DbsTypeUserID extends CBeanFile {
    public final static int USER_SEARCH = 0x00;
    public final static int USER_FAVORITE = 0x21;
    public final static int USER_INFO = 0x12;
    public final static int SONG_REFRESH = 0x03;

    public final static int TASK_ACCOUNT = 0x18;
    public final static int USER_DETAIL = 0x29;
    public final static int COMM_DONE = 0x1a;

    private String gsIniKey;

    public DbsTypeUserID(int fileType, int appType, String userID){
        super(MRAM.mContext, String.format("App%d.sdb", appType), String.format("B%dU%s", fileType, userID), true);
        gsIniKey = String.format("%d_%d_%s_.sdb", appType, fileType, userID);
    }
    public DbsTypeUserID(int fileType, int appType){
        super(MRAM.mContext, String.format("App%d.sdb", appType), String.format("Bean%d", fileType), true);
        gsIniKey = String.format("%d_%d_.sdb", appType, fileType);
    }
    public void setMemoryInt(String key, int saveInt){
        setMemoryString(key, String.format("%d", saveInt));
    }
    public void setMemoryString(String key, String saveString){
        MBAPP.WR_PRIVATE_STRING(gsIniKey + key, saveString, MRAM.mActivity.getDatabasePath("DbsTypeUserID.ini").getAbsolutePath());
    }
    public int getMemoryInt(String key){
        return MAPI.STRING_DEC32(getMemoryString(key));
    }
    public String getMemoryString(String key){
        return MBAPP.RD_PRIVATE_STRING(gsIniKey + key, MRAM.mActivity.getDatabasePath("DbsTypeUserID.ini").getAbsolutePath());
    }
    public void FetchList(final KcTwoListener KcTwoListener){
        new Thread(new Runnable() {
            @Override
            public void run() {
                if (KcTwoListener !=null) {
                    final List<Object> list = getList();
                    MRAM.mActivity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            KcTwoListener.onMessage(0, list);
                        }
                    });
                }

            }
        }).start();
    }
}
